<% add_decidim_page_title(t(".title")) %>
<div class="card" id="partners">
  <div class="item_show__header">
    <h1 class="item_show__header-title">
      <%= t(".title") %>
      <% if allowed_to? :create, :partner %>
         <%= link_to t("actions.new_partner", scope: "decidim.admin"), new_conference_partner_path(current_conference), class: "button button__sm button__secondary new" %>
      <% end %>
    </h1>
  </div>
  <div class="table-stacked">
    <table class="table-list">
      <thead>
        <tr>
          <th><%= t("models.partner.fields.name", scope: "decidim.admin") %></th>
          <th><%= t("models.partner.fields.partner_type", scope: "decidim.admin") %></th>
          <th><%= t("models.partner.fields.link", scope: "decidim.admin") %></th>
          <th><%= t("models.partner.fields.logo", scope: "decidim.admin") %></th>
          <th><%= t("models.partner.fields.actions", scope: "decidim.admin") %></th>
        </tr>
      </thead>
      <tbody>
        <% @partners.each do |partner| %>
          <tr>
            <td data-label="<%= t("models.partner.fields.name", scope: "decidim.admin") %>">
              <%= partner.name %>
            </td>
            <td data-label="<%= t("models.partner.fields.partner_type", scope: "decidim.admin") %>">
              <%= t("#{partner.partner_type}", scope: "decidim.admin.models.partner.types") %>
            </td>
            <td data-label="<%= t("models.partner.fields.link", scope: "decidim.admin") %>">
              <% if partner.link.presence %>
                <%= link_to partner.link, partner.link, target: "_blank" %>
              <% end %>
            </td>
            <td data-label="<%= t("models.partner.fields.logo", scope: "decidim.admin") %>">
              <% if partner.logo.attached? %>
                <%= image_tag(partner.attached_uploader(:logo).variant_url(:thumb)) %>
              <% end %>
            </td>
            <td class="table-list__actions" data-label="<%= t("models.partner.fields.actions", scope: "decidim.admin") %>">
              <button type="button" data-controller="dropdown" data-target="actions-partner-<%= partner.id %>" aria-label="<%= t("decidim.admin.actions.actions_label", resource: partner.name || t("models.partner.name", scope: "decidim.admin")) %>">
                <%= icon "more-fill", class: "text-secondary" %>
              </button>

              <div class="inline-block relative">
                <ul id="actions-partner-<%= partner.id %>" class="dropdown dropdown__action" aria-hidden="true">
                  <% if allowed_to? :update, :partner, partner: partner %>
                    <li class="dropdown__item">
                      <%= link_to edit_conference_partner_path(current_conference, partner), class: "dropdown__button" do %>
                        <%= icon "pencil-line" %>
                        <%= t("actions.edit", scope: "decidim.admin") %>
                      <% end %>
                    </li>

                    <hr>
                  <% end %>

                  <% if allowed_to? :destroy, :partner, partner: partner %>
                    <li class="dropdown__item">
                      <%= link_to conference_partner_path(current_conference, partner), method: :delete, data: { confirm: t("actions.confirm_destroy", scope: "decidim.admin") }, class: "dropdown__button dropdown__button--danger" do %>
                        <%= icon "delete-bin-line" %>
                        <%= t("actions.destroy", scope: "decidim.admin") %>
                      <% end %>
                    </li>
                  <% end %>
                </ul>
              </div>
            </td>
          </tr>
        <% end %>
      </tbody>
    </table>
  </div>
</div>
<%= decidim_paginate @partners %>
